//
//  ActivityAPI.m
//  RainbowFM
//
//  Created by chenli on 14/12/17.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "ActivityAPI.h"
#import "AFAppDotNetAPIClient.h"

@implementation ActivityAPI



-(void)fetchActivityListWithUserID:(NSString *)userID actStateID:(NSString *)actStateId actCategoryID:(NSString *)actCategoryId currentPage:(NSString *)start pageSize:(NSString *)count result:(void (^)(NSArray *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AMS_BASE_URL
                                   parameters:@{@"serviceName" : @"ams_act_list_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"actStateId" : actStateId,
                                                              @"actCategoryId" : actCategoryId,
                                                              @"userId" : userID,
                                                              @"pageSize" : count,
                                                              @"currentPage" : start}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}


-(void)fetchActivityDetailWithActID:(NSString *)actId userID:(NSString *)userId result:(void (^)(NSDictionary *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AMS_BASE_URL
                                   parameters:@{@"serviceName" : @"ams_act_detail_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"actId" : actId,
                                                              @"userId" : userId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];

}


-(void)applyManageWithOper:(NSString *)oper actID:(NSString *)actId userID:(NSString *)userId voteName:(NSString *)name sex:(NSString *)sex_ tel:(NSString *)tel_ result:(void (^)(BOOL))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AMS_BASE_URL
                                   parameters:@{@"serviceName" : @"ams_vote_join_mgr_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"oper" : oper,
                                                              @"actId" : actId,
                                                              @"userId" : userId,
                                                              @"voteName" : name,
                                                              @"sex" : sex_,
                                                              @"tel" : tel_}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES);
//                                              res(responseObject[@"result"],@"");
                                          }
                                          else{
                                              res(NO);
//                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}


-(void)fetchPrizeListWithUserID:(NSString *)userId currentPage:(NSString *)start pageSize:(NSString *)count result:(void (^)(NSArray *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AMS_BASE_URL
                                   parameters:@{@"serviceName" : @"ams_prize_list_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"pageSize" : count,
                                                              @"currentPage" : start}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}


-(void)fetchMyPrizeListWithUserID:(NSString *)userId currentPage:(NSString *)start pageSize:(NSString *)count result:(void (^)(NSArray *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AMS_BASE_URL
                                   parameters:@{@"serviceName" : @"ams_my_prize_list_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"ucode" : @"",
                                                              @"pageSize" : count,
                                                              @"currentPage" : start}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}


-(void)fetchPrizeDetailWithUserID:(NSString *)userId actID:(NSString *)actId result:(void (^)(NSDictionary *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AMS_BASE_URL
                                   parameters:@{@"serviceName" : @"ams_qst_item_detail_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"actId" : actId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}

/**
 *  提交答案
 *
 *  @param actId   <#actId description#>
 *  @param userId  <#userId description#>
 *  @param content <#content description#>
 *  @param res     <#res description#>
 */
-(void)submitQuestionWithWithActID:(NSString *)actId userID:(NSString *)userId ansContent:(NSString *)content result:(void (^)(NSArray *, NSString *))res{
    AFJSONRequestSerializer *jsonRequest = [AFJSONRequestSerializer serializer];
    NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    [jsonRequest setStringEncoding:enc];
    [AFAppDotNetAPIClient sharedClient].requestSerializer = jsonRequest;
    [[AFAppDotNetAPIClient sharedClient].requestSerializer setStringEncoding:enc];
    [[AFAppDotNetAPIClient sharedClient] POST:AMS_BASE_URL
                                   parameters:@{@"serviceName" : @"ams_qst_validate_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"actId" : actId,
                                                              @"ansContent" : content}}
     
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}

-(void)fetchExchangeDetailWithExchID:(NSString *)exchId userID:(NSString *)userId result:(void (^)(NSDictionary *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AMS_BASE_URL
                                   parameters:@{@"serviceName" : @"ams_exch_prize_detail_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"exchId" : exchId,
                                                              @"ucode" : @""}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          
                                      }];
}

@end
